﻿using DNFImagePacks2Manager.QuickTool.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;

namespace DNFImagePacks2Manager.Helpers
{
    public class QuickToolHelper
    {
        public static readonly string ToolDirectory = Path.Combine(AppContext.BaseDirectory, "QuickTool", "Tools");

        public static List<QuickToolBase> GetToolList()
        {
            List<QuickToolBase> toolList = [];
            try
            {
                if (Directory.Exists(ToolDirectory))
                {

                    string[] files = Directory.GetFiles(ToolDirectory);

                    foreach (string file in files)
                    {
                        Debug.WriteLine(file);
                        if (file.EndsWith(".json"))
                        {
                            try
                            {
                                string json = File.ReadAllText(file);
                                var item = JsonConvert.DeserializeObject<QuickToolImgReplace>(json);
                                if (item != null)
                                {
                                    toolList.Add(item);
                                }
                            }
                            catch (Exception) { }
                        }
                    }
                }
            }
            catch (Exception) { }
            return toolList;
        }
    }
}
